package com.w2cx.selenium.business;

import com.w2cx.selenium.base.DriverBase;
import com.w2cx.selenium.operate.SensitiveWordsManageOperate;
import org.openqa.selenium.WebElement;

import java.util.List;

public class SensitiveWordsManageProcess {

    DriverBase driver;
    SensitiveWordsManageOperate swmh;
    public SensitiveWordsManageProcess(DriverBase driver){
        this.driver = driver;
        swmh = new SensitiveWordsManageOperate(driver);
    }

    //添加敏感词
    public void addSensiWord(String wordName){
        //点击基础数据管理
        swmh.clickBaseDataManageMenu();
        //点击敏感词管理
        swmh.clickSensiWordManageMenu();
        //点击添加敏感词
        swmh.clickAddSensiWordBtn();


        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        swmh.inputSensiWordName(wordName);
        swmh.clickAddConfirmBtn();


    }

    //判断是否添加敏感词成功
    public boolean addSensiWordSuccess(String alreadySensiWord){
        List<WebElement> sensiWordList = swmh.getSensiWordList();
        for (WebElement element:sensiWordList){
            if(element.getText().contains(alreadySensiWord)){
                return true;
            }
        }
        return false;
    }


    //删除敏感词
    public void delSensiWord(String workName){
        driver.refresh();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }


        //点击“删除”按钮
        swmh.clickDelSensiWordBtn(workName);
        //点击“确定”按钮
        swmh.clickDelSensiConfirmBtn();



    }

    //判断删除是否成功
    public boolean delSensiWordSuccess(String alreadySensiWord){
        //刷新列表
        driver.refresh();

        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        List<WebElement> list = swmh.getSensiWordList();
        for (WebElement element:list){
            if(element.getText().contains(alreadySensiWord)){
                return false;
            }
        }
        return true;

    }






}
